namespace dXgFx
{
	namespace Win32
	{
		template <typename C>
		class COMObject : public C
		{
		public:
			ULONG STDMETHODCALLTYPE AddRef()
			{
				return ::InterlockedIncrement(static_cast<LONG *>(&this->com_refcount));
			}
			
			//Note that this function needs to be moved into a CPP file
			//since there is operator delete. We have to ensure it is within the same 
			//module as the corresponding operator new.
			ULONG STDMETHODCALLTYPE Release()
			{
				ULONG ret = ::InterlockedDecrement(static_cast<LONG *>(&this->com_refcount));
				if(0 == ret)
					delete this;
				else
					return ret;
			}
		private:
			ULONG com_refcount;
		};
	}
}

